/**   
 * @Title: GetLotteryRecordListCommunicater.java 
 * @Package com.esun.rabbit2.communicaters.lotteryrecord 
 * @Description: 获取购彩记录列表
 * @author: City Jiangsy@500wan.com   
 * @date: 2012-1-9 下午4:44:52  
 * Copyright: (C) 2011 Shenzhen E-sun Sky Net Technology Co.,ltd.
 */
package com.esun.rabbit2.communicaters.lotteryrecord;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

import javax.xml.parsers.ParserConfigurationException;

import org.apache.http.client.ClientProtocolException;
import org.xml.sax.SAXException;

import com.esun.config.BussinessCode;
import com.esun.config.Config;
import com.esun.config.Key;
import com.esun.model.LotteryRecordInfo;
import com.esun.model.UserInfo;
import com.esun.network.ServerCommunicater;
import com.esun.util.log.EDebug;

/**
 * @ClassName: GetLotteryRecordListCommunicater
 * @Description: 获取购彩记录列表
 * @author: City Jiangsy@500wan.com
 * @date: 2012-1-9 下午4:44:52
 * 
 */
public class GetLotteryRecordListCommunicater extends ServerCommunicater {

	private String msgServer;

	public String getMsgServer() {
		return msgServer;
	}

	public void setMsgServer(String msgServer) {
		this.msgServer = msgServer;
	}

	/**
	 * @throws SAXException
	 * @throws ParserConfigurationException
	 * @throws IOException
	 * @throws ClientProtocolException
	 * @Title: isGetLotteryRecord
	 * @Description: (这里用一句话描述这个方法的作用)
	 * @param: @param type 0：未结 ;1：最近中奖; -1：全部
	 * @param: @param pageno 10
	 * @param: @return 设定文件
	 * @return: boolean 返回类型
	 * @throws
	 */
	public boolean isGetLotteryRecord(String type, String pageno) throws ClientProtocolException, IOException, ParserConfigurationException, SAXException {
		boolean isSucceed = false;
		ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
		list.add(mapItem(Config.PASER_MID, BussinessCode.MID_MYLOTTERY_LOTTERYRECORD));
		list.add(mapItem(Config.PASER_CK, UserInfo.getUserInfo().getUserSession()));
		list.add(mapItem(Key.KEY_TYPE, type));
		list.add(mapItem(Key.KEY_PAGENO, pageno));
		list.add(mapItem(Key.KEY_PAGESIZE, Config.PAGE_SIZE));

		super.getServerResponse(list, true);
		setMsgServer(super.getServerMsg());
		if (super.getState() == 100) {
			isSucceed = true;
		}
		return isSucceed;
	}

	public ArrayList<LotteryRecordInfo> getLotteryRecordList() {
		ArrayList<LotteryRecordInfo> list = new ArrayList<LotteryRecordInfo>();
		for (int i = 0; i < super.getListResult().size(); i++) {
			LotteryRecordInfo info = new LotteryRecordInfo();

			info.setLotteryDate(super.getListResult().get(i).get(Key.KEY_ADDTIME));
			info.setLotteryExcept(super.getListResult().get(i).get(Key.KEY_EXPECT));
			info.setLotID(super.getListResult().get(i).get(Key.KEY_LOTTYPE));
			String strDate = super.getListResult().get(i).get(Key.KEY_ADDTIME);
			try {
				info.setLotterTime(strDate.substring(5, strDate.length()));
			} catch (Exception e) {
				info.setLotterTime(Config.NULLMARK);
				// TODO: handle exception
			}
			info.setPayMoney(super.getListResult().get(i).get(Key.KEY_PAYMONEY).substring(0, super.getListResult().get(i).get(Key.KEY_PAYMONEY).indexOf('.') + 3));
			info.setPlayName(super.getListResult().get(i).get(Key.KEY_PLAYNAME));
			info.setGetMoney(super.getListResult().get(i).get(Key.KEY_GETMONEY).substring(0, super.getListResult().get(i).get(Key.KEY_GETMONEY).indexOf('.') + 3));
			info.setID(super.getListResult().get(i).get(Key.KEY_ID));
			info.setProID(super.getListResult().get(i).get(Key.KEY_PROID));
			info.setLotteryState(super.getListResult().get(i).get(Key.KEY_LOTTERYSTATE));
			EDebug.o(this, "lotterystate====" + super.getListResult().get(i).get(Key.KEY_LOTTERYSTATE));
			info.setIssuc(super.getListResult().get(i).get(Key.KEY_ISSUC));
			info.setLotName(super.getListResult().get(i).get(Key.KEY_LOTNAME));
			info.setPlayId(super.getListResult().get(i).get(Key.KEY_WTYPE));
			info.setIsHeMai(super.getListResult().get(i).get(Key.KEY_ISHM));
			info.setUID(super.getListResult().get(i).get(Key.KEY_UID));
			info.setOpenCode(super.getListResult().get(i).get(Key.KEY_OPENCODE));
			info.setFauserName(super.getListResult().get(i).get(Key.KEY_FAUSERNAME));
			list.add(info);
		}
		return list;
	}

	private HashMap<String, String> mapItem(String name, String value) {
		HashMap<String, String> map = new HashMap<String, String>();
		map.put(name, value);
		return map;
	}
}
